#include<iostream>
#include<fstream>
#include<exception>
#include<stdexcept>
#include<cstdlib>

int main() {

  bool success = false;

  try {

    std::ifstream ifs("lapack_test_output.txt");
    int x = 0;
    if (ifs.is_open())
      if ( (ifs >> x).good() )
        if (x == 2)
          success = true;
    ifs.close();

    std::ofstream ofs("lapack_test_output.txt", std::ios_base::out | std::ios_base::trunc);
    if (!ofs.is_open())
      throw std::runtime_error("failed to open output file");
    ofs << int(1) << " " << std::endl;
    ofs.close();

  } catch (std::exception &e) {
    std::cout << "Exception occurred:  " << e.what() << std::endl;
    return EXIT_FAILURE;
  } catch (...) {
    std::cout << "Exception occurred." << std::endl;
    return EXIT_FAILURE;
  }

  if (!success)
    return EXIT_FAILURE;

  return EXIT_SUCCESS;

}
